public class BruteForceSolution {
    public int minOperations(int[] nums, int x) {
        int sum = 0;
        for (int i : nums) {
            sum += i;
        }
        int n = nums.length;
        int count = n + 1;
        for (int i =0; i < n; i++) {
            int sum1 = 0;
            int j = i;
            for (; j < n; j++) {
                if (sum1 >= sum - x) {
                    break;
                }
                sum1 += nums[j];
            }
            if (sum1 == sum - x) {
                count = Math.min(count, n - (j - i));
            }
        }
        return count == n + 1 ? -1 : count;
    }
}
